'''
求城市间的最短路线
直接调用networkx自带的方法 ok
'''

import networkx as nx
import matplotlib.pyplot as plt
import numpy as np

paths=np.array([[0,50,float('inf'),40,25,10],
                [50,0,15,20,float('inf'),25],
                [float('inf'),15,0,10,20,float('inf')],
                [40,20,10,0,10,25],
                [25,float('inf'),20,10,0,55],
                [10,25,float('inf'),25,55,0]])

G=nx.Graph()

for i in range(len(paths)):
    for j in range(len(paths[0])):
        G.add_weighted_edges_from([(i,j,paths[i][j])])
print(G.get_edge_data(2,4))
res=dict(nx.shortest_path_length(G,weight="weight"))
print(res[1][4])
